package com.ruoyi.reservationserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.reservationserver.dao.StadiumDao;
import com.ruoyi.system.domain.Stadium;
import com.ruoyi.reservationserver.service.StadiumService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 球馆表(Stadium)表服务实现类
 *
 * @author makejava
 * @since 2023-07-04 16:21:49
 */
@Service("stadiumService")
public class StadiumServiceImpl extends ServiceImpl<StadiumDao, Stadium> implements StadiumService {
    @Resource
    private StadiumDao stadiumDao;

    @Resource
    private StadiumService stadiumService;

    @Override
    public PageInfo<Stadium> selectStadiumWithPage(Integer page, Integer count) {
        PageHelper.startPage(page, count);

        QueryWrapper<Stadium> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("stadium_id");
        List<Stadium> courtList = stadiumService.list(queryWrapper);


        PageInfo<Stadium> pageInfo=new PageInfo<>(courtList);
        return pageInfo;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param stadiumId 主键
     * @return 实例对象
     */
    @Override
    public Stadium queryById(Integer stadiumId) {
        return this.stadiumDao.queryById(stadiumId);
    }

    @Override
    public Page<Stadium> queryByPage(Stadium stadium, PageRequest pageRequest) {
        return null;
    }


    /**
     * 新增数据
     *
     * @param stadium 实例对象
     * @return 实例对象
     */
    @Override
    public Stadium insert(Stadium stadium) {
        this.stadiumDao.insert(stadium);
        return stadium;
    }

    /**
     * 修改数据
     *
     * @param stadium 实例对象
     * @return 实例对象
     */
    @Override
    public Stadium update(Stadium stadium) {
        this.stadiumDao.update(stadium);
        return this.queryById(stadium.getStadiumId());
    }

    /**
     * 通过主键删除数据
     *
     * @param stadiumId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer stadiumId) {
        return this.stadiumDao.deleteById(stadiumId) > 0;
    }
}
